<template>
	<view class="content" :style="{height: tabHeightVal}">
		<popup-layer ref="popupRef" :direction="'left'">
			<view style="position:absolute;margin-left: 2%;margin-top:15rpx;" @tap="chaxunclose()">
				<image :src="srcfanhui" class="item-icon-sys" mode=""></image>
			</view>
			<view style="height: 93%;font-size: 30rpx;">
				<view class="box" style="text-align: center;">
					<view>筛选</view>
				</view>
				<view class="box">
					<view class="popupspan">资产编码:</view>
					<view class="popupinput"><input type="text" v-model="inputzcbm" placeholder="请输入资产编码"
							placeholder-class="inputff" /></view>
				</view>
				<view class="box">
					<view class="popupspan">资产名称:</view>
					<view class="popupinput">

						<input type="text" v-model="inputzcmc" placeholder="请输入资产名称" placeholder-class="inputff" />

					</view>
				</view>
				<view class="box">
					<view class="popupspan">资产类别:</view>
					<view class="popupinput">
						<view @tap="focusshow($event)" data-id="zclb" class="inputff">{{inputzclb}}</view>
						<!--<input type="text" v-model="inputzclb" placeholder="请输入资产类别" placeholder-class="inputff" @focus="focusshow($event)" data-Id="zclb"/>
				-->
					</view>
				</view>
				<view class="box">
					<view class="popupspan">资产位置:</view>
					<view class="popupinput">
						<!--<input type="text" v-model="inputglbm" placeholder="请输入管理部门" placeholder-class="inputff" @focus="focusshow($event)" data-Id="glbm"/>-->
						<view @tap="focusshow($event)" data-id="zcwz" class="inputff">{{inputzcwz}}</view>
					</view>
				</view>
				<view class="box">
					<view class="popupspan">使用部门:</view>
					<view class="popupinput">
						<view @tap="focusshow($event)" data-id="sybm" class="inputff">{{inputsybm}}</view>
						<!--<input type="text" v-model="inputsybm" placeholder="请输入使用部门" placeholder-class="inputff" @focus="focusshow($event)" data-Id="sybm"/>-->
						</view>
				</view>
				<view class="box">
					<view class="popupspan">使用人:</view>
					<view class="popupinput">
						<view @tap="focusshow($event)" data-id="syr" class="inputff">{{inputsyr}}</view>
						<!--<input type="text" v-model="inputsyr" placeholder="请输入使用人" placeholder-class="inputff" @focus="focusshow($event)" data-Id="syr"/>-->
						</view>
				</view>
			</view>
			<view class="box"
				style="border-bottom: 0px #bfbfbf solid;border-top: 1rpx #bfbfbf solid;padding-top: 5rpx;padding-bottom: 5rpx;">
				<view class="popupspan"
					style="width: 49.5%;text-align: center;border-right: 1px #bfbfbf solid;padding-left: 0rpx;font-size: 28rpx;"
					@tap="chaxunreset()">重置</view>
				<view class="popupinput" style="width: 49.5%;text-align: center;color: #6D8AF9;padding-right: 0rpx;"
					@tap="chaxunok()">确定</view>
			</view>


		</popup-layer>

		<view class="newbutton" :style="{display:disPValue}" @tap="sxchaxun()">
			<image :src="srcsys" class="item-icon-sys" style="float: left;top:5px" mode=""></image>
			<view style="float: left;font-size: 28rpx;color: #bfbfbf;">筛选</view>
		</view>
		<view v-if="this.isupload!=1">
		<view class="dibutton" >
			<view class="childButton" @tap="onclicksys()">
				<image class="item-ico" src="../../static/images/scan.png">
			</view>

		</view>
		</view>
		<!-- 当设置tab-width,指定每个tab宽度时,则不使用flex布局,改用水平滑动 -->
		<me-document-tabs v-model="tabIndex" :tabs="tabs" :fixed="true" ref="metabs" v-on:pChangeType="change"
		:mydata="mydata" :pdzcwz="inputpdzcwz" :isupload="isupload"
			v-on:pback="newback">
		</me-document-tabs>

		<swiper :style="{height: height}" :current="tabIndex" @change="swiperChange">
			<swiper-item v-for="(tab,i) in tabs" :key="i">
				<mescroll-item :i="i" :index="tabIndex" :tabs="tabs" ref="MescrollItem"></mescroll-item>
			</swiper-item>
		</swiper>
		<aui-dialog ref="dialog" :title="auiDialog.title" :msg="auiDialog.msg" :btns="auiDialog.btns"
			:mask="auiDialog.mask" :maskTapClose="auiDialog.maskTapClose" :items="auiDialog.items"
			:theme="auiDialog.theme"></aui-dialog>
			
		<tki-tree ref="tkitree" :selectParent="selectParent" :multiple="multiple" :range="treelist" :foldAll="flod"
			rangeKey="Name" :title="title" @confirm="treeConfirm" @cancel="treeCancel" :selectvalue="selectvalue" @KeyInput="treekeyinput"></tki-tree>
	</view>
</template>

<script>
	import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue"
	import MescrollUni from "@/components/mescroll-uni/mescroll-uni.vue"
	import MescrollItem from "./mescroll-swiper-item.vue";
	import medocumenttabs from "@/components/me-document-tabs/me-document-tabs.vue";
	import popupLayer from "@/components/popup-layer/popup-layer.vue";
	import tkiTree from '@/components/tki-tree-asset/tki-tree.vue';
	import {
		aui
	} from '@/common/aui/js/aui.js';
	import auiDialog from '@/components/aui-dialog/aui-dialog.vue';
	import {
		openComDB,
		executeSQL,
		dropSQL,
		
	} from "@/pages/API/sqllite/sqllite.js";
	var self;
	export default {
		components: {
			MescrollBody,
			MescrollUni,
			MescrollItem,
			medocumenttabs,
			popupLayer,
			tkiTree,
			auiDialog,
		},
		data() {
			return {
				height: "auto", // 需要固定swiper的高度
				tabs: [{
					name: '待拍照',
					code: '',
					count:0,
					id: ''
				}, {
					name: '已拍照',
					code: '',
					count:0,
					id: ''
				}],
				auiDialog: {
					title: '',
					msg: '',
					btns: [{
						name: '确定'
					}],
					mask: true,
					maskTapClose: true,
					items: [],
					theme: 1,
				},
				tabIndex: 0, // 当前tab的下标
				list: [],
				multiple: false,
				selectParent: true,
				flod: false,
				title: "选择资产位置",
				titleColor: "#6D8AF9",
				showTreeValue: false,
				DocumentId: "",
				disPValue: "block",
				srcsys: "../../static/images/icon-sxuan.png",

				inputzcbm: "",
				inputzcmc: "",
				inputzclb: "请选择资产类别 >",
				inputzcwz: "请选择资产位置 >",
				inputsybm:"请选择使用部门 >",
				inputsyr:"请选择使用人 >",	
				inputzclbid: "",
				inputzcwzid: "",
				inputpdzcwz: "",
				inputpdzcwzid: "",
				inputsybmid:"",
				inputsyrid:"",	
				treelist: [],
				multiple: false,
				selectParent: true,
				flod: false,
				title: "选择资产类别",
				selectvalue: "",
				pdselectvalue: "",
				showTreeValue: false,
				ShowQueryValue: false,
				srcfanhui: "../../static/images/icon-fanhui-you.png",
				loginName: "",
				loginid: "",
				loginorgId:"",
				isupload:0,
				mydata:{
					StockCheckResult:'1',
					Name:'盘点单名称',
					_CreatedByUserName:'资产管理员',
					DetailCount:0,
					StockCheckResult:'1',
					CreatedOnDate:'2021-11-09',
					StockCheckTaskCode:'',
					StockCheckTaskName:'',
					StartDeadline:'2021-11-09',
					Deadline:'2021-11-09',
				},
				uploadalldata:[],
				uploadindex:0
			}
		},
		computed: {
			tabHeightVal() {
				return uni.getSystemInfoSync().windowHeight + 'px'
			}
		},
		onBackPress(options) {
		
		},
		onShow() {

		},
		methods: {
			onclicksys(){
		
				// 只允许通过相机扫码
				uni.setStorageSync('scanmytype', "stock");
				uni.navigateTo({
					url: '../home/scan-stock',
				});	
			},
			onclickAdd(){
				uni.navigateTo({
					url: '../stock/StockDocumentAssetAdd',
				});	
				
			},
			onuploaddata(){
				try {
					const newDocumentId = uni.getStorageSync('DocumentId');
					var docuembtfile=uni.getStorageSync("xiazai");
					if(docuembtfile=="1"){
						uni.showModal({
								 title: '提示',
								content:  "请先下载完盘点单后再上传",
								showCancel:false,          
								 success: function (res) {
								if (res.confirm) {
													                              
								 }
							  }
						});
						return;
					}
					var _this = this;
					uni.showNavigationBarLoading();
					executeSQL('nfc', 'select * FROM buildDetailTable where DocumentId="'+this.DocumentId+'"', res => {
						console.log(res);
						if(res!=undefined){
							var _newDataArr = [];
							
							for (var i = 0; i < res.length; i++) {
								if(res[i]['盘点结果']!="未盘" && res[i]['盘点结果']!="盘亏"){
								var _newDataObj = {};
								
								_newDataObj['id'] = res[i].Id;
								_newDataObj['assetId'] = res[i]['AssetId'];
								_newDataObj['assetCode'] =res[i]['资产编码'];
								_newDataObj['checkPosition'] =res[i]['PdStorePlaceId'];						
								_newDataObj['realityUsingUser'] =res[i]['盘点使用人']; //self.loginid;
								_newDataObj['checkResult'] = res[i]['盘点结果'];
								_newDataObj['checkDate'] = res[i]['盘点日期'].replace('-', '').replace('-', '');
								_newDataObj['checkDescription'] = res[i]['盘点备注'];
								_newDataObj['documentId'] =newDocumentId;
								_newDataObj['realityCheckUser'] = self.loginid;//实际盘点人ID
								_newDataObj['realityCheckUserOrgId'] = self.loginorgId;//实际盘点人部门ID
								//_newDataObj['盘点使用人'] = res[i]['盘点使用人'];
								_newDataArr.push(_newDataObj);
								if (_newDataObj['checkResult'].indexOf("正常") != -1) {
									_newDataObj['checkResult'] = "1";
								} else if (_newDataObj['checkResult'].indexOf("未盘") != -1) {
									_newDataObj['checkResult'] = "0";
								}else if (_newDataObj['checkResult'].indexOf("异常") != -1) {
									_newDataObj['checkResult'] = "2";
								}else if (_newDataObj['checkResult'].indexOf("盘盈") != -1) {
									_newDataObj['checkResult'] = "3";
								}
								let ImgUrl= res[i]['ImgUrl'];
								if(ImgUrl!="../../static/images/icon-paizhao.png" && ImgUrl!=""){
									if(ImgUrl.indexOf("gdzcfile")>-1){
										_newDataObj['attachFiles'] = ImgUrl;
									}else{
										const header={
											'Content-Type':'application/json',
											Authorization: uni.getStorageSync("authorization")
										};
										console.log(ImgUrl);
										uni.uploadFile({
										  url: uni.getStorageSync("localurl")+'/console/app/v1/fileOss/upload', // 你的上传API地址
										  filePath: ImgUrl,
										  name: 'file',
										header: header, // 设置请求的 header
										  formData: {
											// 其他要上传的参数
											file:{}
										  },
										  success: (uploadRes) => {
											console.log('图片上传成功', uploadRes);
											let uploadResdata= JSON.parse(uploadRes.data);
											if(uploadResdata.code==2000){
												
												console.log(uploadResdata);											
												_newDataObj['attachFiles'] = JSON.parse(uploadRes.data).data;
											}else{
												uni.showToast({
													icon: 'none',
													title: uploadResdata.msg
												});							
											}
											
										  },
										  fail: (uploadErr) => {
											console.log('上传失败', uploadErr);
										  }
										});
									}
								}
								
								}
								
								
							}
							
								
							
							console.log(_newDataArr);
								var str1 = JSON.stringify(_newDataArr);
								
								this.request_tool({
									url:'/console/app/v1/assetCheck/checkHandleAsset',
									type:'POST',
									data:_newDataArr
								}).then(res => {
											console.error(res);
											if (res.data.code == 2000) {
												uni.hideNavigationBarLoading();
												_this.auiDialog.title = '资产盘点';
												_this.auiDialog.msg = '上传完成';
												_this.auiDialog.items = [];
												_this.auiDialog.btns = [
													{
														name: '确定'
													}
												
												];
												_this.$refs.dialog.show();
												}else{
													setTimeout(function() {
														uni.hideNavigationBarLoading();
													}, 1000);
													uni.showModal({
															 title: '提示',
															content:  '上传失败',
															showCancel:false,          
															 success: function (res) {
															if (res.confirm) {
																				                              
															 }
														  }
													});
												}
											}).catch(err => {
									  console.error(err);
									  
									});
								
							
							
						}
					});
				
				} catch (e) {
				
				}
			},
			fenpiuploaddata(){
				self=this;
				var _this = this;
				var str1 = JSON.stringify(self.uploadalldata[self.uploadindex]);
				
				console.log(self.uploadalldata[self.uploadindex].length);
				uni.request({
					url:uni.getStorageSync("localurl")+'/ServerAPI/AppDocument_SaveFinished', //仅为示例，并非真实接口地址。
					data: {
						Id: this.DocumentId,
						datastr: str1,
						loginName:this.LoginName
					},
					method: "POST",
					success: res6 => {
						if (res6.data.successed == true) {
							if(self.uploadindex==(self.uploadalldata.length-1)){
							uni.hideNavigationBarLoading();
							_this.auiDialog.title = '资产盘点';
							_this.auiDialog.msg = '上传完成';
							_this.auiDialog.items = [];
							_this.auiDialog.btns = [
								{
									name: '确定'
								}
							
							];
							_this.$refs.dialog.show();
							}else{
								self.uploadindex=self.uploadindex+1;
								this.fenpiuploaddata();
							}
						}else{
							setTimeout(function() {
								uni.hideNavigationBarLoading();
							}, 1000);
							uni.showModal({
									 title: '提示',
									content:  res2.data.responseState,
									showCancel:false,          
									 success: function (res) {
									if (res.confirm) {
														                              
									 }
								  }
							});
						}
					},
					fail: () => {
						setTimeout(function() {
							uni.hideNavigationBarLoading();
						}, 1000);
						uni.showToast({
							icon: 'none',
							title: '网络异常,请稍后重试'
						});
					}
				})
			},
			newback() {
				console.log("子页面调用2");

				uni.navigateBack();
			},
			// 轮播菜单
			swiperChange(e) {
				this.tabIndex = e.detail.current
			},
			change() {
				console.log("子页面调用");
				//console.log(this.$refs.MescrollItem[0]);
				this.$refs.MescrollItem[this.tabIndex]._aaaaCCCC();

			},
			qiwxsys() {

				self = this;
				var url = window.location.href.split("#")[
				0]; //该paramUrl 为你使用微信sdk-js相关接口的页面地址 该地址需要配置到应用后台的可信域名下，你也可以理解为项目访问的地址;
				console.log(url);
				uni.request({
					url:uni.getStorageSync("localurl")+'/Documents/WX_GetToken', //仅为示例，并非真实接口地址。
					data: {
						url: url
					},
					method: "POST",
					success: res2 => {
						if (res2.data.successed == true) {
							console.log(res2);
							//alert("调用成功");
							jWeixin.config({
								beta: true, // 必须这么写，否则wx.invoke调用形式的jsapi会有问题
								debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
								appId: res2.data.model.appId, // 必填，企业微信的corpID
								timestamp: res2.data.model.timpstamp, // 必填，生成签名的时间戳
								nonceStr: res2.data.model.noncestr, // 必填，生成签名的随机串
								signature: res2.data.model.signature, // 必填，签名，见 附录-JS-SDK使用权限签名算法
								jsApiList: ["scanQRCode",
									"openLocation"] // 必填，需要使用的JS接口列表，凡是要调用的接口都需要传进来
							});
							jWeixin.ready(function() {
								jWeixin.checkJsApi({
									jsApiList: ["invoke",
									"scanQRCode"], // 需要检测的JS接口列表，所有JS接口列表见附录2,
									success: res => {
										console.log(res);
									}
								});
								jWeixin.invoke("enterpriseVerify", {}, res => {});
								jWeixin.scanQRCode({
									desc: 'scanQRCode desc',
									needResult: 1, // 默认为0，扫描结果由企业微信处理，1则直接返回扫描结果，
									scanType: ["qrCode"], // 可以指定扫二维码还是一维码，默认二者都有
									success: function(res) {
										const resmodel = JSON.parse(res.resultStr);
										if (resmodel.唯一标识 != undefined) {
											uni.request({
												url:uni.getStorageSync("localurl")+'/ServerAPI/Document_Get_Detail_List',
												data: {
													PdloginName:self.loginName,
													DocumentId: self.DocumentId,
													pageSize: 20,
													_r: "813efd8e-1ac0-4cc8-8c35-3d502f680353",
													pageIndex: 0,
													"资产编码": resmodel.资产编码
												},
												success: (res) => {
													console.log(res);
													if (res.data.successed ==
														true) {
														var mydata = [];
														var newrows = JSON
															.parse(res.data
																.rows);
														for (var i = 0; i <
															newrows.length; i++
															) {
															var valueRows =
																newrows[i]
																.toString()
																.split(',');
															var datarow = {};
															for (var j = 0; j <
																res.data
																.columns
																.length; j++) {
																datarow[res
																		.data
																		.columns[
																			j]
																		.字段名] =
																	valueRows[
																		j];
															}
															mydata.push(
																datarow);
														}
														if (mydata.length >
															0) {
															uni.navigateTo({
																url: '../stock/StockDocumentAsset?AssetCode=' +
																	resmodel
																	.资产编码 +
																	'&type=0',
															});
														} else {
															uni.showToast({
																icon: 'none',
																title: '扫描资产不在盘点单内'
															});
														}
													}
												},
												fail: (err) => {
													console.log(err);
													//  请求失败,隐藏加载状态
													this.mescroll.endErr()
												}
											})

										} else {
											uni.showToast({
												icon: 'none',
												title: '无法识别二维码'
											});
										}
									},
									error: function(res) {
										if (res.errMsg.indexOf('function_not_exist') > 0) {
											alert('版本过低请升级')
										}
									}
								});
							});
							//this.model = res.data.model;
						} else {
							console.log(res2);
							uni.showToast({
								icon: 'none',
								title: res2.data.responseState,
								duration: 1500,
							});
						}
						uni.hideNavigationBarLoading();
					},
					fail: () => {

						uni.showToast({
							icon: 'none',
							title: '网络异常,请稍后重试'
						});
					}
				});
			},
			sxchaxun() {
				this.ShowQueryValue = true;
				this.$refs.popupRef.show();
			},
			chaxunclose() {
				this.ShowQueryValue = false;
				this.$refs.popupRef.close();
			},
			chaxunreset() {
				this.inputzcbm = "";
				this.inputzcmc = "";
				this.inputzclb = "请选择资产类别";
				this.inputzcwz = "请选择资产位置";
				this.inputsybm = "请选择使用部门";
				this.inputsyr = "请选择使用人";
				this.inputzclbid = "";
				this.inputzcwzid = "";
				this.inputsybmid = "";
				this.inputsyrid = "";
				uni.removeStorageSync("DetailSearch");
				uni.removeStorageSync("DetailName");
				uni.removeStorageSync("DetailZCLB");
				uni.removeStorageSync("DetailZCWZ");
				uni.removeStorageSync("DetailSYBM");
				uni.removeStorageSync("DetailSYR");

				
			},
			chaxunok() {
				this.ShowQueryValue = false;
				this.$refs.popupRef.close();
				uni.setStorageSync("DetailSearch", this.inputzcbm);
				uni.setStorageSync("DetailName", this.inputzcmc);
				uni.setStorageSync("DetailZCLB", this.inputzclb);
				uni.setStorageSync("DetailZCWZ", this.inputzcwz);
				uni.setStorageSync("DetailSYBM", this.inputsybm);
				uni.setStorageSync("DetailSYR", this.inputsyr);
				this.newload();
				this.change();
			},
			focusshow(e) {
				this.selectvalue = e.currentTarget.dataset.id;
				this.treelist = [];
				this.$refs.tkitree.oldtreeList = "";
				this.$refs.tkitree.servalue = "";

				if (e.currentTarget.dataset.id == "zclb") {
					this.showTree();
					this.title = "请选择资产类别";
					this.loadAssetType();
				} else if (e.currentTarget.dataset.id == "zcwz") {
					this.showTree();
					this.title = "请选择资产位置";
					this.loadStoreplase();
				}else if (e.currentTarget.dataset.id == "sybm") {
					this.showTree();
					this.title = "请选择使用部门";
					this.loadDepartment();
				}else if (e.currentTarget.dataset.id == "syr") {
					if(this.inputsybmid=="" || this.inputsybmid==null){
						uni.showToast({
							icon: 'none',
							title: '请选择使用部门'
						});
						return;
					}else{
						this.showTree();
						this.title="请选择使用人";
						this.loadsybmProfile();
					}
				}

			},
			// 确定回调事件
			treeConfirm(e) {
				this.showTreeValue = false;
				console.log(this.selectvalue);
				if (this.selectvalue == "zclb") {
					this.inputzclb = e[0].label;
					this.inputzclbid = e[0].id;
				} else if (this.selectvalue == "zcwz") {
					this.inputzcwz = e[0].label;
					this.inputzcwzid = e[0].id;
				}else if (this.selectvalue == "pdzcwz") {
					console.log(e[0]);
					if(e[0].childLength>0){
						uni.showToast({
							icon: 'none',
							title: '盘点位置必须选择到末级'
						});
						this.$refs.tkitree._show();
					}else{
					uni.setStorageSync("CurrStore",e[0].id);
					uni.setStorageSync("CurrStoreName",e[0].label);
					this.inputpdzcwz = e[0].label;
					this.inputpdzcwzid = e[0].id;
					}
				}else if(this.selectvalue=="sybm"){
						this.inputsybm=e[0].label;
						this.inputsybmid=e[0].id;
					}else if(this.selectvalue=="syr"){
						this.inputsyr=e[0].label;
						this.inputsyrid=e[0].id;
					}

			},
			// 取消回调事件
			treeCancel(e) {
				this.showTreeValue = false;
				console.log(e)
			},
			treekeyinput(value){
				let bmid="";
				if(this.selectvalue=="zrr"){
					bmid=this.inputglbmid;
				}
				if(this.selectvalue=="syr"){
					bmid=this.inputsybmid;
				}
				
				this.request_tool({
					url:'/console/app/v1/operator/pageData',
					type:'POST',
					data:{"orgId":bmid,"userName":value,"current":0,"pageSize":100}
				}).then(res => {
						//console.error(res);
						if(res!=undefined){
						if (res.data.code == 2000) {
							//console.log(res.data.data);
							//self.treelist= res.data.data;
							let newtreelist=[];
							for(var i=0;i<res.data.data.records.length;i++){
								let resitem= res.data.data.records[i];
								let treeitem={
									id:resitem.id,
									label:resitem.userName,
									isEnabled:resitem.isEnabled,
									checked:false,
									children:[],
								};
								newtreelist.push(treeitem);
							}
							self.treelist=newtreelist;
							setTimeout(function () {
							  uni.hideNavigationBarLoading();
							}, 2000);
							this.$refs.tkitree.oldtreeList="";
							this.$refs.tkitree.servalue=value;
							this.showTree();
							//this.model = res.data.model;
						}else{
							uni.showToast({
								icon: 'none',
								title: res.data.msg
							});							
						}
						}
						}).catch(err => {
				  console.error(err);
				  
				});
				
				//this.treelist=newtreeList;
			},
			// 显示树形选择器
			showTree() {
				this.showTreeValue = true;
				this.$refs.tkitree._show();
			},
			loadAssetType() {
				self = this;

				uni.showNavigationBarLoading();
				this.request_tool({
					url:'/console/app/v1/asset-category/treeData',
					type:'POST',
					data:{}
				}).then(res => {
						console.error(res);
						if (res.data.code == 2000) {
							console.log(res.data.data);
							self.treelist= res.data.data;
							setTimeout(function () {
							  uni.hideNavigationBarLoading();
							}, 2000);
							this.$refs.tkitree.oldtreeList="";
							this.$refs.tkitree.servalue="";
							this.showTree();
							//this.model = res.data.model;
						}else{
							uni.showToast({
								icon: 'none',
								title: res.data.msg
							});							
						}
						}).catch(err => {
				  console.error(err);
				  
				});

			},
			loadStoreplase() {
				self = this;
			
				uni.showNavigationBarLoading();
				let sql = "select * from buildStore";
				console.log(sql);
				executeSQL('nfc', sql, res => {
					//this.productList = mydata;
					// 接口返回的当前页数据列表 (数组)
					if(res.code!=-1404){
						console.log(res);
						if(res.length>0){
							let mydata=res;
							//self.treelist=JSON.parse(res[0]["value"]);
							let treedata=JSON.parse(res[0]["value"]);
							let managePositionIds=JSON.parse(self.mydata.orgPosition);
							let newtreedata=[];
							self.filterParentNode(managePositionIds,treedata,newtreedata);
							self.treelist=newtreedata;
							//self.mydata.orgPosition;
							console.log(self.treelist);
							setTimeout(function() {
								uni.hideNavigationBarLoading();
							}, 1000);
						}
					}
				})
				
			
			
			},
			
			loadDepartment(){
				self=this;
				uni.showNavigationBarLoading();
		
				self.request_tool({
					url:'/console/app/v1/organization/treeData',
					type:'POST',
					data:{}
				}).then(res => {
						console.error(res);
						if (res.data.code == 2000) {
							console.log(res.data.data);
							self.treelist= res.data.data;
							setTimeout(function () {
							  uni.hideNavigationBarLoading();
							}, 2000);
							this.$refs.tkitree.oldtreeList="";
							this.$refs.tkitree.servalue="";
							this.showTree();
							//this.model = res.data.model;
						}else{
							uni.showToast({
								icon: 'none',
								title: res.data.msg
							});							
						}
						}).catch(err => {
				  console.error(err);
				  
				});
			},
			loadsybmProfile(){
				self=this;
				uni.showNavigationBarLoading();
				self.request_tool({
					url:'/console/app/v1/operator/pageData',
					type:'POST',
					data:{"orgId":self.inputsybmid,"current":0,"pageSize":100}
				}).then(res => {
						console.error(res);
						if(res!=undefined){
						if (res.data.code == 2000) {
							console.log(res.data.data);
							//self.treelist= res.data.data;
							let newtreelist=[];
							for(var i=0;i<res.data.data.records.length;i++){
								let resitem= res.data.data.records[i];
								let treeitem={
									id:resitem.id,
									label:resitem.userName,
									isEnabled:resitem.isEnabled,
									checked:false,
									children:[],
								};
								newtreelist.push(treeitem);
							}
							self.treelist=newtreelist;
							setTimeout(function () {
							  uni.hideNavigationBarLoading();
							}, 2000);
							this.$refs.tkitree.oldtreeList="";
							this.$refs.tkitree.servalue="";
							this.showTree();
							//this.model = res.data.model;
						}else{
							uni.showToast({
								icon: 'none',
								title: res.data.msg
							});							
						}
						}
						}).catch(err => {
				  console.error(err);
				  
				});
				
			},
			newload() {
				self = this;
				//const listdata = uni.getStorageSync("userinfo");
				 let userInfo = uni.getStorageSync("userInfo");
				// console.log(userInfo);
				self.loginName = JSON.parse(userInfo).userName;
				let pageNum = 1; // 页码, 默认从1开始
				let pageSize = 10; // 页长, 默认每页10条
				var sql = "";
				var sql2 = "";
				sql = "select * from MybuildTable where Id='"+self.DocumentId+"' AND 盘点总数>0";
				executeSQL('nfc', sql, res => {
					//this.productList = mydata;
					// 接口返回的当前页数据列表 (数组)
					if(res.code!=-1404){
						console.log(res);
						if(res.length>0){
							self.mydata=res[0];
						}
					}
				})
				
				
				var mydataservalue = {
					PdloginName:self.loginName,
					DocumentId: self.DocumentId,
					pageSize: 5,
					_r: "813efd8e-1ac0-4cc8-8c35-3d502f680353",
					pageIndex: 0,
				}
				var mydataservalue11 = {
								Id: self.DocumentId,
							}
				
				sql2="select * from buildDetailTable where DocumentId='"+self.DocumentId+"'";
				const mydataser = uni.getStorageSync("DetailSearch");
				if (mydataser == undefined) {
					mydataser = "";
				}
				if (mydataser != "") {
					mydataservalue["-资产编码"] = mydataser;
					sql2=sql2+" and 资产编码 like '%"+mydataser+"%'";
				}

				const mydataname = uni.getStorageSync("DetailName");
				if (mydataname == undefined) {
					mydataname = "";
				}
				if (mydataname != "") {
					mydataservalue["-资产名称"] = mydataname;
					sql2=sql2+" and 资产名称 like '%"+mydataname+"%'";
				}
				console.log(mydataname);
				const mydatazclb = uni.getStorageSync("DetailZCLB");
				if (mydatazclb == undefined) {
					mydatazclb = null;
				}
				if (mydatazclb != null && mydatazclb!="" && mydatazclb!="请选择资产类别 >" && mydatazclb!="请选择资产类别") {
					mydataservalue["AssetTypeId"] = mydatazclb;
					
				}
				const mydatazcwz = uni.getStorageSync("DetailZCWZ");
				if (mydatazcwz == undefined) {
					mydatazcwz = null;
				}
				if (mydatazcwz != null && mydatazcwz!="" && mydatazcwz!="请选择资产位置 >" && mydatazcwz!="请选择资产位置") {
					mydataservalue["StorePlaceId"] = mydatazcwz;
					sql2=sql2+" and StorePlaceId = '"+mydatazcwz+"'";
				}
				
				const mydatasybm = uni.getStorageSync("DetailSYBM");
				if (mydatasybm == undefined) {
					mydatasybm = null;
				}
				if (mydatasybm != null && mydatasybm!="" && mydatasybm!="请选择使用部门 >" && mydatasybm!="请选择使用部门") {
					sql2=sql2+" and 使用部门 = '"+mydatasybm+"'";
				}
				
				const mydatasyr = uni.getStorageSync("DetailSYR");
				if (mydatasyr == undefined) {
					mydatasyr = null;
				}
				if (mydatasyr != null && mydatasyr!="" && mydatasyr!="请选择使用人 >" && mydatasyr!="请选择使用人") {
					sql2=sql2+" and 使用人 = '"+mydatasyr+"'";
				}
				var sqlwp=sql2+" and 盘点结果='未盘'";
				console.log(sqlwp);
				executeSQL('nfc', sqlwp, res => {
					//this.productList = mydata;
					// 接口返回的当前页数据列表 (数组)
					if(res.code!=-1404){
						console.log(res);
						self.tabs[0].count=res.length;
						self.dpcount = res.length;
						//if(res.length>0){
						//	self.mydata=res[0];
						//}
					}
				})
				//mydataservalue["StockCheckResult"] = 0;
				
				var sqlzc=sql2+" and 盘点结果='正常'";
				executeSQL('nfc', sqlzc, res => {
					//this.productList = mydata;
					// 接口返回的当前页数据列表 (数组)
					if(res.code!=-1404){
						//console.log(res);
						self.tabs[1].count=res.length;
						self.dpcount = res.length;
						//if(res.length>0){
						//	self.mydata=res[0];
						//}
					}
				})
				
				var sqlyc=sql2+" and 盘点结果='异常'";
				executeSQL('nfc', sqlyc, res => {
					//this.productList = mydata;
					// 接口返回的当前页数据列表 (数组)
					if(res.code!=-1404){
						//console.log(res);
						self.tabs[2].count=res.length;
						self.dpcount = res.length;
						//if(res.length>0){
						//	self.mydata=res[0];
						//}
					}
				})
				//mydataservalue["StockCheckResult"] = 2;
				var sqlpk=sql2+" and 盘点结果='盘亏'";
				//console.log(sqlpk);
				executeSQL('nfc', sqlpk, res => {
					//this.productList = mydata;
					// 接口返回的当前页数据列表 (数组)
					if(res.code!=-1404){
						//console.log(res);
						self.tabs[4].count=res.length;
						self.dpcount = res.length;
						//if(res.length>0){
						//	self.mydata=res[0];
						//}
					}
				})
				
				var sqlpy=sql2+" and 盘点结果='盘盈'";
				executeSQL('nfc', sqlpy, res => {
					//this.productList = mydata;
					// 接口返回的当前页数据列表 (数组)
					if(res.code!=-1404){
						//console.log(res);
						self.tabs[3].count=res.length;
						self.dpcount = res.length;
						//if(res.length>0){
						//	self.mydata=res[0];
						//}
					}
				})
				
			}
			,
			filterParentNode(ids,options,options2){
			      if(Array.isArray(ids)&&ids.length>0){
			        options.forEach(option=>{	
						if(ids.includes(option.id)){
							let newoption={
								"id": option.id,
								"code": option.code,
								"label": option.label,
								"isEnabled": option.isEnabled,
								"levelCode": option.levelCode,
								"parentLevelCode": option.parentLevelCode,
								"pathCode": option.pathCode,
								"entityName": option.entityName,
							}							
							let childrenarr=[];
							if(option.children){
							  this.filterParentNode(ids,option.children,childrenarr);
							}
							newoption.children=childrenarr;
							
							options2.push(newoption);
						}else{							
								if(option.children){
									let childrenarr=[];
								  this.filterParentNode(ids,option.children,childrenarr);
								  if(childrenarr.length>0){
									  let newoption={
									  	"id": option.id,
									  	"code": option.code,
									  	"label": option.label,
									  	"isEnabled": "0",
									  	"levelCode": option.levelCode,
									  	"parentLevelCode": option.parentLevelCode,
									  	"pathCode": option.pathCode,
									  	"entityName": option.entityName,
									  }
										newoption.children=childrenarr;
										options2.push(newoption);
								  }
								}
							}
			         
			        });
			      }
			    },
			request_tool(options){
			 // 在这里可以对请求头进行一些设置
			 let baseUrl = uni.getStorageSync("localurl"); 
			 let userInfo = uni.getStorageSync("userInfo");
			 if (userInfo) {
			 	options.data['userLevelCode'] =JSON.parse(userInfo).levelCode;
			 	options.data['loginUserId'] = JSON.parse(userInfo).id;
			 }
			 let userDept = uni.getStorageSync("userDept");
			 console.log(userDept);
			 if (userDept) {
			 	options.data['loginUserDeptLevelCode'] = userDept.levelCode;
			 	options.data['loginUserDeptId'] = userDept.id;
			 }
			 let currentRole = uni.getStorageSync("userRoles");
			  console.log(currentRole);
			 if (currentRole) {
			 	options.data['roleLevelCode'] = currentRole[0].levelCode;
			 	options.data['roleId'] = currentRole[0].id;
			 }
			  options.header = {
			      'Content-Type':'application/json',
			      Authorization: uni.getStorageSync("authorization")
			 }
			
			    return new Promise((resolve, reject) => {
			        uni.request({
			            url: baseUrl + options.url || '',
			            method: options.type || 'POST',
			            data: options.data || {},
			            header: options.header || {}      
			        }).then(data => {
			            let [err, res] = data;        
			            resolve(res);
			        }).catch(error => {
			            reject(error)
			        })
			    });
			}
		},

		onLoad(options) {
			
			// 需要固定swiper的高度
			self = this;
			
			this.inputpdzcwz =uni.getStorageSync("CurrStoreName");
			this.inputpdzcwzid = uni.getStorageSync("CurrStore");
			const userinfo = uni.getStorageSync("userInfo");
			this.loginid=JSON.parse(userinfo).id;
			this.loginorgId=JSON.parse(userinfo).orgId;
			this.loginName = JSON.parse(userinfo).loginName;
			
			this.height = uni.getSystemInfoSync().windowHeight + 'px'
			self.DocumentId = options.id;
			self.isupload=options.isupload;
			if(options.isupload==1){
				// #ifdef APP-PLUS
				var webView = this.$mp.page.$getAppWebview();
				// 修改buttons
				webView.setTitleNViewButtonStyle(0, {
				width: '0',
				});
				
				webView.setTitleNViewButtonStyle(1, {
				width: '0',
				});
				// #endif
			}
			uni.setStorage({
				key: 'DocumentId',
				data: options.id
			});
			uni.removeStorageSync("DetailSearch");
			uni.removeStorageSync("DetailName");
			uni.removeStorageSync("DetailZCLB");
			uni.removeStorageSync("DetailZCWZ");
			uni.removeStorageSync("DetailSYBM");
			uni.removeStorageSync("DetailSYR");
			this.newload();
			
			this.tabs[0].code = options.code;
			this.tabs[1].code = options.code;
			this.tabs[2].code = options.code;
			this.tabs[3].code = options.code;
			var pdsys = uni.getStorageSync("pdsys");
			if (pdsys == "1") {
				uni.setStorageSync("pdsys", "0");
				this.qiwxsys();
			}

		}
	}
</script>

<style>
	.item-icon-sys {
		width: 40upx;
		height: 40upx;
	}
	
	.item-ico {
		width: 30upx;
		height: 30upx;
	}

	.newbutton {
		font-style: normal;
		height: 64rpx !important;
		line-height: 60rpx !important;
		z-index: 9990;
		width: 110rpx !important;
		box-sizing: border-box;
		margin-right: 10rpx;
		border: none !important;
		border-radius: 8rpx !important;
		font-size: 34rpx !important;
		position: absolute;
		right: 20rpx !important;
		color: #FFFFFF;
		text-align: center;
		top: 496rpx;
		
	}
	
	.dibutton {
	
		font-style: normal;
		height: 82rpx !important;
		line-height: 80rpx !important;
		z-index: 9990;
		width: 100% !important;
		box-sizing: border-box;
		border-radius: 20rpx !important;
		font-size: 34rpx !important;
		position: absolute;
		text-align: center;
		top: 94%;
		
	}
	.dibutton .childButton{
		width: 100%;
		float: left;
		background-color: #6D8AF9;
		color: #fff;
		}

	.content {
		background-color: #edf1f4;
	}

	.box {
		width: 600rpx;
		border-bottom: 1px #CCCCCC solid;
		height: 80rpx;
		line-height: 80rpx;
		z-index: 9999;
	}

	.box .popupspan {
		width: 36.5%;
		display: inline-block;
		height: 80rpx;
		line-height: 80rpx;
		padding-left: 3.5%;
		color: #5a5a5a;
	}

	.box .popupinput {
		width: 52%;
		text-align: right;
		display: inline-block;
		height: 80rpx;
		line-height: 80rpx;
		padding-right: 30rpx;
		float: right;
	}

	.box .popupinput input {
		height: 100%;
		line-height: 100%;
		font-size: 30rpx;
	}

	.inputff {
		color: #BEBEBE;
		font-size: 30rpx;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.box .popupinput {
		font-size: 30rpx;
	}
</style>
